#include "header.h"

#ifndef WIN32
#include <termios.h>

char getch()
{
    char c;
    termios oldt;
    tcgetattr(STDIN_FILENO, &oldt);
    termios newt = oldt;
    newt.c_lflag &= ~ECHO;
    newt.c_lflag &= ~ICANON;
    tcsetattr(STDIN_FILENO, TCSANOW, &newt);
    cin >> c;
    tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
    return c;
}

void Sleep(unsigned int  useconds )
{
    // 1 milliseconds = 1000 microsecond.
    // Windows Sleep uses miliseconds
    // linux usleep uses microsecond
    // and since the default
    // usage of the code was under windows 
    // so the argument is   coming in millisecond.
    usleep( useconds * 1000 );
}

#endif

extern ofstream debugfile;

void debug(string s)
{
  debugfile << s << endl;
}

void debugint(string s, int n)
{
  debugfile << s << " " << n << endl;
}

room doRoomsCollide(const room one, const room two)
{
  int left = max(one.x,two.x);
  int right = min((one.x+one.w),(two.x+two.w));
  int top = max(one.y,two.y);
  int bottom = min((one.y+one.h),(two.y+two.h));
  if (left >= right or top >= bottom)
  {
    return room(); //Returns -1 in all variables here
  }
  else
  {
    return room(left, top, right-left, bottom-top); //Returns rectangle of collision
  }
}
